#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,a[100010],tr[800010],num[100010],ans,id[100010],mp[100010];
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("reporter.in","r",stdin);
	freopen("reporter.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
		for(int i=1;i<=n;i++){
			num[1]=num[2]=num[3]=num[4]=0;
			for(int j=i;j<=n;j++)mp[a[j]]=0;
			for(int j=i;j<=n;j++){
				num[mp[a[j]]]--;
				mp[a[j]]++;
				num[mp[a[j]]]++;
				if(k==4&&num[1]>=1&&num[2]>=1&&num[3]>=1&&num[4]>=1)ans++;
				if(k==3&&num[1]>=1&&num[2]>=1&&num[3]>=1)ans++;
				if(k==2&&num[1]>=1&&num[2]>=1)ans++;
				if(k==1&&num[1]>=1)ans++;
			}
		}
		cout<<ans;
	return 0;
}
/*

*/
